dynamic class classes.ww_interface.Fightbox extends MovieClip
{
    var EXPLOSION_MC;
    var GAME_CLASS;
    var LAST_FIGHT;
    var SKIP;
    var SKIP_MODE;
    var UNITS_MC;
    var WINNER;
    var _parent;
    var _visible;
    var _x;
    var dieces_limit;
    var dieces_no;
    var docX;
    var explosion1;
    var explosion2;
    var i;
    var military1;
    var military2;
    var onEnterFrame;
    var ran1;
    var ran2;
    var rubbish;
    var ter1;
    var ter2;
    var ultraSkipA;
    var ultraSkipB;
    var ultraSkipP1;
    var ultraSkipP2;
    var winNO;
    var winTemp;

    function Fightbox()
    {
        super();
        this.EXPLOSION_MC = this._parent._parent.EXPLOSION_MC;
        this.UNITS_MC = this._parent._parent.UNITS_MC;
        var root = this;
        this.SKIP_MODE = false;
        this._visible = false;
        var __reg4 = 1;
        while (__reg4 <= 8) 
        {
            this["d" + __reg4]._visible = false;
            ++__reg4;
        }
        this.SKIP.onRelease = function ()
        {
            _global.SOUNDS.playSound("Click- głośniejszy.wav");
            root.SKIP_MODE = true;
            root._visible = false;
            root.ultraSkip();
        }
        ;
    }

    function registerGame(g)
    {
        this.GAME_CLASS = g;
    }

    function fight(A, B)
    {
        if (!this.SKIP_MODE) 
        {
            this.LAST_FIGHT = getTimer();
            this.resetDieces();
            this._visible = true;
            this.military1._visible = this.military2._visible = true;
            this.explosion1.gotoAndStop(1);
            this.explosion2.gotoAndStop(1);
            this.military1.un.text = A.unitsNO;
            this.military2.un.text = B.unitsNO;
            this.military1.army_ico.gotoAndStop(A.army);
            this.military1.army_ico.filters = [];
            this.military1.army_ico.units.gotoAndStop(A.unitsNO);
            this.military1.flag.gotoAndStop(A.player);
            this.military2.army_ico.gotoAndStop(B.army);
            this.military2.army_ico.filters = [];
            this.military2.army_ico.units.gotoAndStop(B.unitsNO);
            this.military2.flag.gotoAndStop(B.player);
            this.ter1.gotoAndStop(A.player);
            this.ter2.gotoAndStop(B.player);
            var __reg8 = 0;
            var __reg7 = 0;
            this.WINNER = undefined;
            var __reg5 = 0;
            while (__reg5 < A.unitsNO) 
            {
                var __reg6 = this.random2(5) + 1;
                __reg8 = __reg8 + __reg6;
                ++__reg5;
            }
            __reg5 = 0;
            while (__reg5 < B.unitsNO) 
            {
                __reg6 = this.random2(5) + 1;
                __reg7 = __reg7 + __reg6;
                ++__reg5;
            }
            if (__reg8 > __reg7) 
            {
                this.winTemp = A;
                this.winNO = 1;
            }
            else 
            {
                this.winTemp = B;
                this.winNO = 2;
            }
            this.setUltraSkip(__reg8, __reg7, A, B);
            this.ran1.setTo(__reg8);
            this.ran2.setTo(__reg7);
            _global.SOUNDS.playSound("kości.wav");
            this.onEnterFrame = mx.utils.Delegate.create(this, this.fightFinished);
            this.dieces_limit = A.unitsNO + B.unitsNO;
            this.dieces_no = 0;
            this.rubbish = new Array();
            this.throwDices(A.player, A.unitsNO, 1);
            this.throwDices(B.player, B.unitsNO, 2);
            return;
        }
        __reg8 = 0;
        __reg7 = 0;
        this.WINNER = undefined;
        __reg5 = 0;
        while (__reg5 < A.unitsNO) 
        {
            __reg6 = this.random2(5) + 1;
            __reg8 = __reg8 + __reg6;
            ++__reg5;
        }
        __reg5 = 0;
        while (__reg5 < B.unitsNO) 
        {
            __reg6 = this.random2(5) + 1;
            __reg7 = __reg7 + __reg6;
            ++__reg5;
        }
        if (__reg8 > __reg7) 
        {
            var __reg9 = this;
            this.EXPLOSION_MC._x = this.UNITS_MC._x + B.unitsMC._x;
            this.EXPLOSION_MC._y = this.UNITS_MC._y + B.unitsMC._y;
            this.EXPLOSION_MC.gotoAndPlay(2);
            this.winTemp = A;
            this.EXPLOSION_MC.onEnterFrame = mx.utils.Delegate.create(this, this.fightFinished2);
            return;
        }
        this.EXPLOSION_MC._x = this.UNITS_MC._x + A.unitsMC._x;
        this.EXPLOSION_MC._y = this.UNITS_MC._y + A.unitsMC._y;
        this.EXPLOSION_MC.gotoAndPlay(2);
        this.winTemp = B;
        this.EXPLOSION_MC.onEnterFrame = mx.utils.Delegate.create(this, this.fightFinished2);
    }

    function setUltraSkip(pow1, pow2, A, B)
    {
        this.ultraSkipA = A;
        this.ultraSkipB = B;
        this.ultraSkipP1 = pow1;
        this.ultraSkipP2 = pow2;
    }

    function ultraSkip()
    {
        delete this.onEnterFrame;
        if (this.ultraSkipP1 > this.ultraSkipP2) 
        {
            var __reg2 = this;
            this.EXPLOSION_MC._x = this.UNITS_MC._x + this.ultraSkipB.unitsMC._x;
            this.EXPLOSION_MC._y = this.UNITS_MC._y + this.ultraSkipB.unitsMC._y;
            this.EXPLOSION_MC.gotoAndPlay(2);
            this.winTemp = this.ultraSkipA;
            this.EXPLOSION_MC.onEnterFrame = mx.utils.Delegate.create(this, this.fightFinished2);
            return;
        }
        this.EXPLOSION_MC._x = this.UNITS_MC._x + this.ultraSkipA.unitsMC._x;
        this.EXPLOSION_MC._y = this.UNITS_MC._y + this.ultraSkipA.unitsMC._y;
        this.EXPLOSION_MC.gotoAndPlay(2);
        this.winTemp = this.ultraSkipB;
        this.EXPLOSION_MC.onEnterFrame = mx.utils.Delegate.create(this, this.fightFinished2);
    }

    function initCountdowns()
    {
        this.ran1.countTo();
        this.ran2.countTo();
    }

    function fightFinished()
    {
        if (this.SKIP_MODE == false) 
        {
            if (this.ran1.finished() && this.ran2.finished() && this.explosion1._currentframe == 1 && this.explosion2._currentframe == 1) 
            {
                if (this.winNO == 1) 
                {
                    this.explosion2.gotoAndPlay(2);
                }
                else 
                {
                    this.explosion1.gotoAndPlay(2);
                }
            }
            if (this.explosion1._currentframe == 7) 
            {
                this.military1._visible = false;
            }
            if (this.explosion2._currentframe == 7) 
            {
                this.military2._visible = false;
            }
            if (this.explosion1._currentframe == this.explosion1._totalframes || this.explosion2._currentframe == this.explosion2._totalframes) 
            {
                this.WINNER = this.winTemp;
                this.GAME_CLASS.fightFinished();
                this._visible = false;
                delete this.onEnterFrame;
            }
        }
    }

    function fightFinished2()
    {
        if (this.EXPLOSION_MC._currentframe == 7) 
        {
            this.WINNER = this.winTemp;
            this.GAME_CLASS.fightFinished();
        }
        if (this.EXPLOSION_MC._currentframe == this.EXPLOSION_MC._totalframes) 
        {
            delete this.EXPLOSION_MC.onEnterFrame;
        }
    }

    function random2(z)
    {
        return Math.round(Math.random() * z);
    }

    function throwDices(player, units, terr)
    {
        var root = this;
        var i = 0;
        for (;;) 
        {
            if (i >= units) 
            {
                return;
            }
            var __reg2 = this["d" + player].duplicateMovieClip("dice" + player + "_" + i, terr * 10 + i);
            this.rubbish.push(__reg2);
            __reg2._x = this["gen" + terr]._x;
            __reg2._xscale = __reg2._yscale = 70;
            if (terr == 1) 
            {
                __reg2.docX = __reg2._x + 15;
            }
            if (terr == 2) 
            {
                __reg2.docX = __reg2._x - 15 - __reg2._width;
            }
            __reg2._y = this["gen" + terr]._y + i * 25;
            __reg2.i = (i + 2) / 2;
            __reg2.onEnterFrame = function ()
            {
                this._x = this._x + (this.docX - this._x) / this.i;
                if (Math.abs(this._x - this.docX) < 1) 
                {
                    ++root.dieces_no;
                    if (root.dieces_no == root.dieces_limit) 
                    {
                        root.initCountdowns();
                    }
                    this._x = this.docX;
                    delete this.onEnterFrame;
                }
            }
            ;
            ++i;
        }
    }

    function resetWinner()
    {
        this.WINNER = undefined;
    }

    function resetSkipMode()
    {
        this.SKIP._visible = true;
        this.SKIP_MODE = false;
    }

    function resetDieces()
    {
        var __reg2 = 0;
        for (;;) 
        {
            if (__reg2 >= this.rubbish.length) 
            {
                return;
            }
            this.rubbish[__reg2].removeMovieClip();
            ++__reg2;
        }
    }

    function kill()
    {
        delete this.EXPLOSION_MC.onEnterFrame;
    }

}
